#!/usr/bin/python3

def sqlsave(get_time,a,b):
    import pymysql

    # 打开数据库连接
    db = pymysql.connect(host='localhost',
                         user='root',
                         password='guotai',
                         database='mqtt_test')

    # 使用 cursor() 方法创建一个游标对象 cursor
    cursor = db.cursor()

    cursor = db.cursor()

    # SQL 插入语句
    # sqlQuery = " INSERT INTO test (Name, Email, Age) VALUE (%s,%s,%s) "
    # value = ('Mike', '123456@163.com', 20)
    sql = """INSERT INTO test(get_time, a, b) VALUE  (%s,%s,%s)"""
    value = (get_time, a, b)
    try:
        # 执行sql语句
        cursor.execute(sql)
        # 提交到数据库执行
        db.commit()
        print("存上了！")
    except:
        # 如果发生错误则回滚
        db.rollback()
        print("妹存上！")

    # 关闭数据库连接
    db.close()

